package Collection.List;

import java.util.Iterator;
import java.util.LinkedList;

public class LinkedListDemo {
    public static void main(String[] args) {
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.addFirst("a");
        linkedList.addFirst("b");
        linkedList.addLast("c");

        System.out.println(linkedList);
        System.out.println("---迭代器遍历------");
        Iterator<String> iterator = linkedList.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }


        System.out.println("Linklist的栈结构：先进后出");
        //压栈  -->push()
        linkedList.push("d");
        System.out.println(linkedList);
        //弹栈 ---->pop()     首先会弹出a,因为a是最先加入的
        linkedList.pop();
        System.out.println(linkedList);
        //检查有没有 弹出元素，并查询弹出元素
        System.out.println(linkedList.peek());
        linkedList.pop();
        linkedList.pop();
        linkedList.pop();
        //如果没有元素，则显示为null
        System.out.println(linkedList.peek());
        //push 压栈   pop 弹栈  peek 判断是否有元素，有 则显示即将弹栈的元素
        linkedList.push("a");
        linkedList.push("b");
        System.out.println(linkedList);
        linkedList.pop();
        System.out.println(linkedList);
        System.out.println(linkedList.peek());
        LinkedList<Iterator> a = new LinkedList<>();
        System.out.println(a.contains(a));

    }
}
